home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / ms_sh21s.zip / SH210 / SRC / SH6.C < prev    next >
C/C++ Source or Header  |  1992-12-14  |  8KB  |  254 lines

  1. /* MS-DOS SHELL - Data Declarations
  2.  *
  3.  * MS-DOS SHELL - Copyright (c) 1990,1,2 Data Logic Limited and Charles Forsyth
  4.  *
  5.  * This code is based on (in part) the shell program written by Charles
  6.  * Forsyth and is subject to the following copyright restrictions:
  7.  *
  8.  * 1.  Redistribution and use in source and binary forms are permitted
  9.  *     provided that the above copyright notice is duplicated in the
  10.  *     source form and the copyright notice in file sh6.c is displayed
  11.  *     on entry to the program.
  12.  *
  13.  * 2.  The sources (or parts thereof) or objects generated from the sources
  14.  *     (or parts of sources) cannot be sold under any circumstances.
  15.  *
  16.  *    $Header: /usr/users/istewart/src/shell/sh2.1/RCS/sh6.c,v 2.4 1992/12/14 10:54:56 istewart Exp $
  17.  *
  18.  *    $Log: sh6.c,v $
  19.  *    Revision 2.4  1992/12/14  10:54:56  istewart
  20.  *    BETA 215 Fixes and 2.1 Release
  21.  *
  22.  *    Revision 2.3  1992/11/06  10:03:44  istewart
  23.  *    214 Beta test updates
  24.  *
  25.  *    Revision 2.2  1992/09/03  18:54:45  istewart
  26.  *    Beta 213 Updates
  27.  *
  28.  *    Revision 2.1  1992/07/10  10:52:48  istewart
  29.  *    211 Beta updates
  30.  *
  31.  *    Revision 2.0  1992/04/13  17:39:09  Ian_Stewartson
  32.  *    MS-Shell 2.0 Baseline release
  33.  *
  34.  *
  35.  */
  36.  
  37. #include <sys/types.h>
  38. #include <stddef.h>
  39. #include <stdio.h>
  40. #include <signal.h>
  41. #include <errno.h>
  42. #include <setjmp.h>
  43. #include <stdlib.h>
  44. #include <limits.h>
  45. #include <dirent.h>
  46. #include <unistd.h>
  47. #include <string.h>
  48. #ifdef OS2
  49. #define INCL_DOSSESMGR
  50. #include <os2.h>
  51. #endif
  52. #include "sh.h"
  53.  
  54. #ifdef OS2
  55. static char    *Copy_Right1 = "MS-DOS SH Version 2.1 (%s) - %s (OS/2 %d.%d)\n";
  56. #else
  57. static char    *Copy_Right1 = "MS-DOS SH Version 2.1 (%s) - %s (DOS %d.%d)\n";
  58. #endif
  59. static char    *Copy_Right2 = "Copyright (c) Data Logic Ltd and Charles Forsyth 1990, 91, 92\n";
  60. char        **ParameterArray = (char **)NULL; /* Parameter array    */
  61. int        ParameterCount = 0;    /* # entries in parameter array    */
  62. int        ExitStatus;        /* Exit status            */
  63. bool        ExpansionErrorDetected;
  64.                 /* interactive (talking-type wireless)    */
  65. bool        InteractiveFlag = FALSE;
  66. bool        ProcessingEXECCommand;    /* Exec mode            */
  67. bool        UseConsoleBuffer = FALSE;/* Flag from dofc to        */
  68.                     /* GetConsoleInput        */
  69. int        AllowMultipleLines;    /* Allow continuation onto    */
  70.                     /* Next line            */
  71. int        Current_Event = 0;    /* Current history event    */
  72. bool        ChangeInitLoad = FALSE;    /* Change load .ini pt.        */
  73. unsigned char    GlobalFlags = 0;    /* Other global flags        */
  74.  
  75. int        *FailReturnPoint;    /* Current fail jump address    */
  76. int        *ErrorReturnPoint;    /* Current error jump address    */
  77. int        DisabledVariables = 0;    /* Disabled variables        */
  78.  
  79. #ifdef OS2
  80. unsigned int    SW_intr;        /* Interrupt flag        */
  81. char        path_line[FFNAME_MAX];    /* Execution path        */
  82. #else
  83.                     /* Swap mode            */
  84. int        Swap_Mode = SWAP_EXPAND | SWAP_DISK;
  85. #endif
  86. Break_C        *Break_List;    /* Break list for FOR/WHILE        */
  87. Break_C        *Return_List;    /* Return list for RETURN        */
  88. Break_C        *SShell_List;    /* SubShell list for EXIT        */
  89. bool        RestrictedShellFlag = FALSE;    /* Restricted shell    */
  90.                 /* History processing enabled flag    */
  91. bool        HistoryEnabled = FALSE;
  92.  
  93. void        *FunctionTree = (void *)NULL;    /* Function tree    */
  94. FunctionList    *CurrentFunction = (FunctionList *)NULL;
  95. void        *AliasTree = (void *)NULL;    /* Alias tree        */
  96. #ifdef OS2
  97. void        *JobTree = (void *)NULL;    /* job tree        */
  98. bool        ExitWithJobsActive = FALSE;    /* Exit flag        */
  99. int        CurrentJob = 0;            /* No current        */
  100. int        PreviousJob = 0;        /* Previous Job        */
  101. #endif
  102.  
  103. Save_IO        *SSave_IO;    /* Save IO array            */
  104. int        NSave_IO_E = 0;    /* Number of entries in Save IO array    */
  105. int        MSave_IO_E = 0;    /* Max Number of entries in SSave_IO    */
  106. S_SubShell    *SubShells;    /* Save Vars array            */
  107. int        NSubShells = 0;    /* Number of entries in SubShells    */
  108. int        MSubShells = 0;    /* Max Number of entries in SubShells    */
  109. int        LastNumberBase = -1;    /* Last base entered        */
  110.  
  111. Word_B        *WordListBlock;    /* Current Word List            */
  112. Word_B        *IOActionBlock;    /* Current IO List            */
  113. int        InterruptTrapPending;    /* Trap pending            */
  114. int        Execute_stack_depth;    /* execute function recursion    */
  115.                     /* depth            */
  116. void        *VariableTree = (void *)NULL;    /* Variable dictionary    */
  117. VariableList    *CurrentDirectory;    /* Current directory        */
  118. char        *LastUserPrompt;    /* Last prompt output        */
  119. char        *LastUserPrompt1;    /* Alternate Last prompt output    */
  120. char        IFS[] = "IFS";        /* Inter-field separator    */
  121. char        PS1[] = "PS1";        /* Prompt 1            */
  122. char        PS2[] = "PS2";        /* Prompt 2            */
  123. char        PS3[] = "PS3";        /* Prompt 3            */
  124. char        PS4[] = "PS4";        /* Prompt 4            */
  125. char        PathLiteral[] = "PATH";
  126. char        HomeVariableName[] = "HOME";
  127. char        ShellVariableName[] = "SHELL";
  128. char        HistoryFileVariable[] = "HISTFILE";
  129. char        HistorySizeVariable[] = "HISTSIZE";
  130. char        *ComspecVariable= "COMSPEC";
  131. char        *ParameterCountVariable = "#";
  132. char        *ShellOptionsVariable = "-";
  133. char        *StatusVariable = "?";
  134. char        *spcl2 = "$`'\"";
  135. char        SecondsVariable[] = "SECONDS";
  136. char        RandomVariable[] = "RANDOM";
  137. char        LineCountVariable[] = "LINENO";
  138. char        *OldPWDVariable = "OLDPWD";
  139. char        *PWDVariable = "PWD";
  140. char        *ENVVariable = "ENV";
  141. bool        FirstReadFromUser = TRUE;
  142. #ifdef OS2
  143. char        BATExtension[] = ".cmd";
  144. #else
  145. char        BATExtension[] = ".bat";
  146. #endif
  147. char        SHELLExtension[] = ".sh";
  148. char        EXEExtension[] = ".exe";
  149. char        COMExtension[] = ".com";
  150. char        *NotFound = "not found";
  151. char        *BasicErrorMessage = "%s: %s\n";
  152. char        *DirectorySeparator = "/";
  153. char        LastWordVariable[] = "_";
  154. char        OptArgVariable[] = "OPTARG";
  155. char        OptIndVariable[] = "OPTIND";
  156. char        MailCheckVariable[] = "MAILCHECK";
  157. char        *Trap_DEBUG = "~DEBUG";
  158. char        *Trap_ERR = "~ERR";
  159. char        LIT_export[] = "export";
  160. char        LIT_exit[] = "exit";
  161. char        LIT_exec[] = "exec";
  162. char        LIT_history[] = "history";
  163. char        LIT_REPLY[] = "REPLY";
  164. char        LIT_LINES[] = "LINES";
  165. char        LIT_COLUMNS[] = "COLUMNS";
  166. char        *ListVarFormat = "%s=%s\n";
  167. char        *Outofmemory1 = "Out of memory";
  168. char        *LIT_Emsg = "%s: %s (%s)\n";
  169. char        *LIT_2Strings = "%s %s\n";
  170. char        *LIT_3Strings = "%s %s%s\n";
  171.  
  172. #ifdef OS2
  173. STARTDATA    *SessionControlBlock;    /* Start a session info        */
  174. #endif
  175.  
  176. /*
  177.  * Global program mode information
  178.  */
  179.  
  180. struct ExecutableProcessing     ExecProcessingMode;
  181.  
  182. /*
  183.  * Modified getopt values
  184.  */
  185.  
  186. int        OptionIndex = 1;    /* optind            */
  187. int        OptionStart;        /* start character        */
  188. char        *OptionArgument;    /* optarg            */
  189.  
  190. /*
  191.  * Device directory.  The length of this string is defined by the variable
  192.  * LEN_DEVICE_NAME_HEADER
  193.  */
  194.  
  195. char        *DeviceNameHeader = "/dev/";
  196.  
  197.                 /* I/O stacks                */
  198. IO_Args        ioargstack[NPUSH];
  199. IO_State    iostack[NPUSH];
  200.  
  201.                 /* Temporary I/O argument        */
  202. IO_Args        temparg = {
  203.     (char *)NULL,        /* Word                    */
  204.     (char **)NULL,        /* Word list                */
  205.     0,                /* File descriptor            */
  206.     AFID_NOBUF,            /* Buffer id                */
  207.     0L,                /* File position            */
  208.     0,                /* Offset in buffer            */
  209.     (IO_Buf *)NULL        /* Buffer                */
  210. };
  211.  
  212. int        MemoryAreaLevel;/* Current allocation area        */
  213. bool        InParser;    /* In parser flag            */
  214. long        flags = 0L;    /* Command line flags            */
  215. char        null[] = "";    /* Null value                */
  216. char        ConsoleLineBuffer[LINE_MAX + 1]; /* Console line buffer    */
  217.  
  218.                 /* Current environment            */
  219. ShellFileEnvironment    e = {
  220.     (char *)NULL,        /* Current line buffer            */
  221.     (char *)NULL,        /* Current pointer in line        */
  222.     (char *)NULL,        /* End of line pointer            */
  223.     iostack,            /* I/O Stack pointers            */
  224.     iostack - 1,
  225.     (int *)NULL,
  226.     FALSE,            /* End of file processing        */
  227.     FDBASE,            /* Base file handler            */
  228.     (Word_B *)NULL,        /* Globbing word block            */
  229.     (ShellFileEnvironment *)NULL    /* Previous Env pointer        */
  230. };
  231.  
  232. /*
  233.  * Some defines to print version and release info
  234.  */
  235.  
  236. #define str(s)        # s
  237. #define xstr(s)        str(s)
  238.  
  239. #ifdef OS2
  240. #define OS_VERSION    _osmajor / 10
  241. #else
  242. #define OS_VERSION    _osmajor
  243. #endif
  244.  
  245. /*
  246.  * The only bit of code in this module prints the version number
  247.  */
  248.  
  249. void    PrintVersionNumber (FILE *fp)
  250. {
  251.     fprintf (fp, Copy_Right1, xstr (RELEASE), __DATE__, OS_VERSION, _osminor);
  252.     fputs (Copy_Right2, fp);
  253. }
  254.